// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/*
 * @Author: qiulin_JXGM ql1746365080@gmail.com
 * @Date: 2024-10-10 11:11:06
 * @LastEditors: qiulin 1746365080@qq.com
 * @LastEditTime: 2025-01-08 19:47:53
 * @FilePath: \SGFEM\Import\BDFImport\ControlData\DATA\DynamicSolution.cpp
 */

#include "DynamicSolutionConditions.h"

#include <cstring>

#include "Utility/Logging/SGLogger.h"

CONTROLDATA_ENTRY_PARSER_REG (METHOD)

CONTROLDATA_ENTRY_PARSER_REG (CMETHOD)

CONTROLDATA_ENTRY_PARSER_REG (TSTEP)

CONTROLDATA_ENTRY_PARSER_REG (FREQUENCY)

CONTROLDATA_ENTRY_PARSER_REG (SDAMPING)

CONTROLDATA_ENTRY_PARSER_REG (IC)

CONTROLDATA_ENTRY_PARSER_REG (MODESELECT)

CONTROLDATA_ENTRY_PARSER_REG (RCROSS)

CONTROLDATA_ENTRY_PARSER_REG (RANDOM)

// 对于METHOD将额外补充ANALYSYS，TODO(bug 001) AnalysisTypes未区分直接法与模态法，仍需补充
SG::DataStructure::Common::Status SG::Import::BDF::CONTROLDATA::ParseMETHOD (SG::DataStructure::FEM::Subcase::ControlInfo& controlInfo,
                                                                             SG::Utility::SGParameter&                     subcase)
{
    SG::Utility::SGParameter ParameterMETHOD;
    ParameterMETHOD.AddString (SG::DataStructure::FEM::Subcase::SC_MAINKEY, controlInfo.m_Vaule);
    if (controlInfo.m_vecKeys.size () != 0)
    {
        ParameterMETHOD.AddStringArray (SG::DataStructure::FEM::Subcase::SC_VECTORKEY, controlInfo.m_vecKeys);
    }
    if (controlInfo.m_mapKeys.size () != 0)
    {
        SG::Utility::SGParameter mapParameter;
        for (auto iter : controlInfo.m_mapKeys)
        {
            mapParameter.AddString (iter.first, iter.second);
        }
        ParameterMETHOD.AddValue (SG::DataStructure::FEM::Subcase::SC_MAPKEY, mapParameter);
    }
    subcase.AddValue ("METHOD", ParameterMETHOD);

    SG::Utility::SGParameter ParameterAnalysis;
    switch (SG::Import::BDF::CaseDataEntryParserFactory::GetInstance ()->m_SolutionSequences)
    {
    case 103:
    case 105:
    case 111:
    case 112:
        ParameterAnalysis.AddString (SG::DataStructure::FEM::Subcase::SC_MAINKEY,
                                     std::to_string (SG::Import::BDF::CaseDataEntryParserFactory::GetInstance ()->m_SolutionSequences));
        break;
    default:
        break;
    }
    subcase.AddValue ("SOL", ParameterAnalysis);
    return SG::DataStructure::Common::Status::STATUS_Success;
}

SG::DataStructure::Common::Status SG::Import::BDF::CONTROLDATA::ParseCMETHOD (SG::DataStructure::FEM::Subcase::ControlInfo& controlInfo,
                                                                              SG::Utility::SGParameter&                     subcase)
{
    SG::Utility::SGParameter ParameterCMETHOD;
    ParameterCMETHOD.AddString (SG::DataStructure::FEM::Subcase::SC_MAINKEY, controlInfo.m_Vaule);
    if (controlInfo.m_vecKeys.size () != 0)
    {
        ParameterCMETHOD.AddStringArray (SG::DataStructure::FEM::Subcase::SC_VECTORKEY, controlInfo.m_vecKeys);
    }
    if (controlInfo.m_mapKeys.size () != 0)
    {
        SG::Utility::SGParameter mapParameter;
        for (auto iter : controlInfo.m_mapKeys)
        {
            mapParameter.AddString (iter.first, iter.second);
        }
        ParameterCMETHOD.AddValue (SG::DataStructure::FEM::Subcase::SC_MAPKEY, mapParameter);
    }
    subcase.AddValue ("CMETHOD", ParameterCMETHOD);

    SG::Utility::SGParameter ParameterAnalysis;
    ParameterAnalysis.AddString (SG::DataStructure::FEM::Subcase::SC_MAINKEY, "110");
    subcase.AddValue ("SOL", ParameterAnalysis);
    return SG::DataStructure::Common::Status::STATUS_Success;
}

CONTROLDATA_ENTRY_PARSER_IMPL (TSTEP)

CONTROLDATA_ENTRY_PARSER_IMPL (FREQUENCY)

CONTROLDATA_ENTRY_PARSER_IMPL (SDAMPING)

CONTROLDATA_ENTRY_PARSER_IMPL (IC)

CONTROLDATA_ENTRY_PARSER_IMPL (MODESELECT)

CONTROLDATA_ENTRY_PARSER_IMPL (RCROSS)

CONTROLDATA_ENTRY_PARSER_IMPL (RANDOM)
